﻿#pragma once

#include <QObject>
#include <QTcpSocket>


class TCPClient : public QObject
{
	Q_OBJECT

public:
	TCPClient(QObject *parent);
	~TCPClient();

	bool ConnectToHost(const QString& host, const unsigned int port);

	bool SendMessage(const QByteArray& data);
	bool SendMessageAndWaitAns(const QByteArray& data, QByteArray& ans, int timeoutMS = 3000);

signals:
	void ResponseReceieved(const QByteArray& data);
	void TcpDisconnected();
	void TcpErrored(QAbstractSocket::SocketError error);
private slots:
	void OnDisconnected();
	void OnConnected();

	void OnReadyRead();

	void OnError(QAbstractSocket::SocketError error);

private:
	QString m_ip;
	QString m_port;
	QTcpSocket m_socket;
};
